<template>
  <div v-if="hotCity">
    <div class="hot-wrap">
      <div class="title">热门城市</div>
      <div
        class="hot-item"
        v-for="item in hotCity.cities"
        :key="item.cityId"
        @click="choose(item)"
      >
        {{ item.name }}
      </div>
    </div>
    <div class="classify" v-for="item in otherCity" :key="item.prefix">
      <div class="title">{{ item.prefix | toUpper }}</div>
      <div
        class="item"
        v-for="val in item.cities"
        :key="val.cityId"
        @click="choose(val)"
      >
        {{ val.name }}
      </div>
    </div>
  </div>
</template>

<script>
// import { cityApi } from "@/utils/api";
import { mapMutations, mapGetters, mapActions } from "vuex";
export default {
  mounted() {
    this.getCityListAsync();
  },
  methods: {
    ...mapMutations("city", ["changeCity"]),
    ...mapActions("city", ["getCityListAsync"]),
    choose(item) {
      // console.log(item.name);
      // this.$store.commit("changeCity", { name: item.name });

      localStorage.setItem("name", item.name);
      localStorage.setItem("id", item.cityId);
      this.changeCity({ name: item.name, id: item.cityId });
      this.$router.go(-1);
    },
  },
  computed: {
    ...mapGetters("city", ["hotCity", "otherCity"]),
  },
  filters: {
    toUpper(val) {
      return val.toUpperCase();
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  width: 100%;
  height: 24px;
  font-size: 16px;
  line-height: 24px;
  background: #bbb;
  padding-left: 20px;
}
.item {
  margin: 0 20px;
  border-bottom: 1px solid #bbb;
  font-size: 16px;
  height: 30px;
  line-height: 30px;
}

.hot-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  .hot-item {
    width: 30%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    .ell();
    border: 1px solid #bbb;
    // padding: 10px 0;
    // margin: 10px 0;
  }
}
</style>
